import {
  get,
  post
} from "../../untils/db"


Page({
  data: {
    showActionsheet: false,
    sheet: false,
    sex: "请选择性别",
    groups: [
      {text: '男',value: 0},
      {text: '女',value: 1},
    ],
    group: [],
    obj: {
      sex: "",
      nickName: "",
      employeeId: "",
      phonenumber: "",
      deptId: "",
      deptName: "",
      password: "",
      deptName: "请选择部门",
      code:"1"
    }
  },
  async onLoad() {
    let res = await get("/api/department/list", "", "")
    res.data.data.forEach((item, index) => {
      item.text = item.deptName
      item.value = index
    })
    this.setData({
      group: res.data.data
    })
  },
  close: function () {
    this.setData({
      showActionsheet: false,
      sheet: false
    })
  },
  btnClick(e) {
    this.setData({
      'obj.sex': this.data.groups[e.detail.value].value,
      sex: this.data.groups[e.detail.value].text
    }, () => {
      console.log(this.data.obj.sex);
    })
    this.close()
  },
  btnClicksed(e) {
    console.log(e);
    this.setData({
      "obj.deptId": this.data.group[e.detail.value].deptId,
      'obj.deptName': this.data.group[e.detail.value].text
    }, () => {
      console.log(this.data.obj.deptName);
    })
    this.close()
  },
  tan() {
    this.setData({
      showActionsheet: true
    })
  },
  tiao() {
    this.setData({
      sheet: true
    })
  },



  gonghao(e) {
    this.setData({
      "obj.employeeId": e.detail.value
    })
  },
  name(e){
    this.setData({
      "obj.nickName": e.detail.value
    })
  },
  phone(e){
    this.setData({
      "obj.phonenumber": e.detail.value
    })
  },
  bodyid(e){
    this.setData({
      "obj.cardId": e.detail.value
    })
  },
  password(e){
    this.setData({
      "obj.password": e.detail.value
    })
  },
  async zhuce(){
  let res=await post("/api/register",this.data.obj,"")
  if(res.data.code==200){
    wx.navigateTo({
      url: '../ing/ing',
    })
    wx.showToast({
      title: '填写成功',
      icon:"success"
    })
  }else{
    wx.showToast({
      title: res.data.msg,
      icon:"error"
    })
  }
  }
})